#include "logmgr.h"
#include <string.h>
#include <stdarg.h>

FILE* LogMgr::m_pFile = stdout;

int LogMgr::print( const char* szFunc,
				  const int szLine,
				  const char* szTime,
				  const char* format, 
				  ...)
{
	if ( !m_pFile )
		return 0;
	
	int nRes = 0;
	
	char buff[MAX_LOG_BUFF] = {0};
	
	sprintf(buff,"[DEBUG] %s(%d) %s\n",szFunc,szLine,szTime);
	buff[MAX_LOG_BUFF] = 0;
	
	nRes += fwrite(buff,sizeof(char),strlen(buff),m_pFile);
	memset(buff,0,MAX_LOG_BUFF);

	va_list ap;
	va_start(ap,format);

	sprintf(buff,format,ap);
	va_end(ap);

	buff[MAX_LOG_BUFF] = 0;
	nRes += fwrite(buff,sizeof(char),strlen(buff),m_pFile);
		
	return nRes;
}